package com.terrace.generator.core.constant;

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.terrace.generator.core.exception.ConfigFileException;

/**
 * 配置文件--config/config.properties
 * 
 * @author jiangyg
 *
 */
public class ConfigConstant {
	
	private static final Logger logger = LoggerFactory.getLogger(ConfigConstant.class);

	private static final Properties UTILS_CONFIG_PROPERTIES = new Properties();
	
	/**
	 * 获取配置属性的值
	 * @param key
	 * @return
	 */
	public static String value(String key) {
		if (UTILS_CONFIG_PROPERTIES.isEmpty()) {
			synchronized (ConfigConstant.class) {
				if (UTILS_CONFIG_PROPERTIES.isEmpty()) {
					final String configPath = "/config.properties";
					try {
						UTILS_CONFIG_PROPERTIES.load(ConfigConstant.class.getResourceAsStream(configPath));
					} catch (Exception ex) {
						logger.error("代码生成器配置文件[" + configPath + "]加载出错：", ex);
						throw new ConfigFileException("代码生成器配置文件[" + configPath + "]加载出错：", ex);
					}
				}
			}
		}
		return UTILS_CONFIG_PROPERTIES.getProperty(key);
	}
	
}
